package com.gzhryc.shared_device.oem.h5.mng.controllers.ops;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.gzhryc.common.data.dto.AjaxResult;
import com.gzhryc.common.data.dto.ListResult;
import com.gzhryc.common.exceptions.LogicException;
import com.gzhryc.servlet.DtoConstants;
import com.gzhryc.servlet.WebUtils;
import com.gzhryc.servlet.annotation.Route;
import com.gzhryc.shared_device.common.payment.dao.db.AlipayAbnormalPayOrder;
import com.gzhryc.shared_device.common.payment.services.AlipayAbnormalPayOrderService;
import com.gzhryc.shared_device.common.payment.services.WXPayAbnormalPayOrderService;
import com.gzhryc.shared_device.common.payment.services.dto.AlipayAbnormalPayOrderSearch;
import com.gzhryc.shared_device.oem.h5.mng.WebConstants;

public class AlipayAbnormalPayOrderController {

    @Route(value = { "/ops/order/ali/abnoraml/list.html" })
    public String list(HttpServletRequest request) {
        return "/ops/order/ali_abnoraml/list.html";
    }

    @Route(value = "/ops/order/ali/abnoraml/list.data")
    public ListResult<AlipayAbnormalPayOrder> listData(HttpServletRequest request) {
        ListResult<AlipayAbnormalPayOrder> result = new ListResult<>(DtoConstants.NULL_DATA, "暂无数据");
        AlipayAbnormalPayOrderSearch search = WebUtils.getParameter(request, AlipayAbnormalPayOrderSearch.class);
        Integer pageNo = WebUtils.getInteger(request, "page", 1);
        Integer pageLimit = WebUtils.getInteger(request, "limit", WebConstants.PAGE_LIMIT);

        result.getBody().setTotal(AlipayAbnormalPayOrderService.self().countBySearch(search));
        List<AlipayAbnormalPayOrder> data = AlipayAbnormalPayOrderService.self().findBySearch(search,pageNo,pageLimit);
        if(data != null && data.size() > 0){
            result.setCode(DtoConstants.SUCCESS,null);
            result.getBody().setData(data);
        }
        return result;
    }

    @Route(value = { "/ops/order/ali/abnoraml/info.html" })
    public String info(HttpServletRequest request) {
        String tradeNo = WebUtils.getString(request, "tradeNo");
        AlipayAbnormalPayOrder abnormalPayOrder = AlipayAbnormalPayOrderService.self().getByTradeNo(tradeNo);
        WebUtils.setAttribute(request,abnormalPayOrder);
        return "/ops/order/ali_abnoraml/info.html";
    }


    @Route(value = { "/ops/order/wx/abnoraml/check_del.do" })
    public AjaxResult checkOrDel(HttpServletRequest request) {
        AjaxResult result = new AjaxResult(DtoConstants.EXECUTE_ERROR, "删除失败");
        String tradeNo = WebUtils.getString(request, "tradeNo");
        try {
            if(WXPayAbnormalPayOrderService.self().checkToDelete(tradeNo)){
                result.setCode(DtoConstants.SUCCESS,null);
            }
        } catch (LogicException e) {
            result.setMsg(e.getMessage());
        }
        return result;
    }

    @Route(value = { "/ops/order/wx/abnoraml/del.do" })
    public AjaxResult del(HttpServletRequest request) {
        AjaxResult result = new AjaxResult(DtoConstants.EXECUTE_ERROR, "删除失败");
        String tradeNo = WebUtils.getString(request, "tradeNo");
        try {
            if(WXPayAbnormalPayOrderService.self().deleteById(tradeNo)){
                result.setCode(DtoConstants.SUCCESS,null);
            }
        } catch (LogicException e) {
            result.setMsg(e.getMessage());
        }
        return result;
    }

}
